package com.flame.shapeville.component.task3;

import javafx.animation.TranslateTransition;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Shape;
import javafx.util.Duration;
import lombok.Getter;

/**
 * Abstract base class for all shapes used in Task 3.
 * Provides common layout and animation functionality for shape rendering.
 *
 * @author Flame Dev Team
 * @version 1.0
 * @since 2025-05-12
 */
public abstract class JfShape {

    /**
     * The main pane containing the visual representation of the shape.
     */
    @Getter
    AnchorPane shape = new AnchorPane();

    /**
     * A detailed pane that includes additional explanations and formulas.
     */
    @Getter
    AnchorPane detailedShape = new AnchorPane();

    /**
     * The JavaFX Shape object representing the geometry of this shape.
     */
    @Getter
    Shape graphics;

    /**
     * The translate transition animation applied to the shape.
     */
    TranslateTransition tt;

    /**
     * X-coordinate center of the drawing area.
     */
    int centerX;

    /**
     * Y-coordinate center of the drawing area.
     */
    int centerY;

    /**
     * Default constructor.
     * Sets up initial layout sizes and center coordinates.
     */
    JfShape() {
        shape.setPrefSize(480, 240);
        centerX = 240;
        centerY = 120;
        detailedShape.setPrefSize(480, 240);
    }

    /**
     * Initializes the base appearance settings for a shape.
     *
     * @param shape the shape to be styled
     */
    void initBaseParams(Shape shape) {
        shape.setFill(null);
        shape.setStroke(Color.CYAN);
        shape.setStrokeWidth(2);
        initTranslate(shape);
    }

    /**
     * Sets up the translation animation for the shape.
     *
     * @param shape the shape to animate
     */
    private void initTranslate(Shape shape) {
        tt = new TranslateTransition();
        tt.setNode(shape);
        tt.setDuration(Duration.seconds(1));
        tt.setFromX((this.shape.getPrefWidth() - 2) / 4);
        tt.setToX(0);
    }

    /**
     * Abstract method to initialize detailed view with extra explanation and formula.
     *
     * @param graphicsSize the size used for rendering the detailed shape
     */
    abstract void initDetailed(int graphicsSize);

    /**
     * Plays the translation animation.
     */
    public void translateAnimation() {
        tt.play();
    }
}
